package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper {
    void insert(Orders orders);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);


    @Select("select * from orders where number = #{outTradeNo}")
    Orders getByNumber(String outTradeNo);

    @Update(" update orders set status = #{orderStatus}, checkout_time = #{checkoutTime} ,pay_status = #{orderPaidStatus} where number = #{orderNumber} ")
    void updateStatus(Integer orderPaidStatus, Integer orderStatus, LocalDateTime checkoutTime, String orderNumber);


    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    @Delete("delete from orders where id=#{id}")
    void deleteById(Long id);


    @Select("select count(*) from orders where status = #{completed} ")
    Integer countByStatus(Integer completed);


    @Update("update orders set status = #{completed} where id = #{id}")
    void adminUpdate(Long id, Integer completed);

    //查询超时订单
    @Select("select * from orders where status=#{status} and order_time<#{time}")
    List<Orders> getTimeOutOrders(Integer status, LocalDateTime time);


    Double turnoverStatistics(LocalDateTime beginTime, LocalDateTime endTime,Integer status);

    Integer orderStatistics(LocalDateTime beginTime, LocalDateTime endTime, Integer status);


}
